package variabilitysmelldetection.measurement.models;

import java.text.NumberFormat;

import variabilitysmelldetection.measurement.measures.Measure;


public class AttributeItem extends Item {
	private ComponentItem componentItem;
	private String visibility;
	private String type;
	private boolean isArrayType;
	private boolean isPrimitiveType;
	
	public AttributeItem(ComponentItem parent, String name) {
		super(parent.getName(), name);
		this.componentItem = parent;
	}
	
	public String getParentName() {
		return componentItem.getParentName();
	}
			
	public String getVisibility() {
		return visibility;
	}

	public void setVisibility(String visibility) {
		this.visibility = visibility;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean isArrayType() {
		return isArrayType;
	}

	public void setArrayType(boolean isTypeArray) {
		this.isArrayType = isTypeArray;
	}

	public boolean isPrimitiveType() {
		return isPrimitiveType;
	}

	public void setPrimitiveType(boolean isTypePrimitive) {
		this.isPrimitiveType = isTypePrimitive;
	}

	public String getFieldsAndMeasuresNames(){
		StringBuilder dados = new StringBuilder();
		dados.append("feature");
		dados.append(";");
		dados.append("class");
		dados.append(";");
		dados.append("attribute");
		dados.append(";");
		dados.append("visibility");
		dados.append(";");
		for (Measure m : getMeasures()) {
			dados.append(m.getAcronym());
			dados.append(";");
		}
		return dados.toString();
	}
	
	public String toCSV() {
		StringBuffer buffer = new StringBuffer();		
		buffer.append(componentItem.getParentName()); //feature
		buffer.append(";");
		buffer.append(componentItem.getName()); // class
		buffer.append(";");
		buffer.append(getName()); // attribute
		buffer.append(";");
		buffer.append(getVisibility());
		buffer.append(";");
		for (Measure m : getMeasures()) {
			buffer.append(NumberFormat.getNumberInstance().format(m.getValue()));
			buffer.append(";");
		}
		
		return buffer.toString();
	}

}